package net.hn.hnms.biz.equipment.until;

import net.hn.hnms.biz.equipment.link.DeptLinkService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.system.api.domain.vo.SysDeptNameForCodeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 智呈物联 nzw
 * @date 2023/2/2
 */
@Component
public class MineName {
    private DeptLinkService deptLinkService;

    @Autowired
    public void setDeptLinkService(DeptLinkService deptLinkService) {
        this.deptLinkService = deptLinkService;
    }

    public String getMineName(String mineCode){
        R<List<SysDeptNameForCodeVO>> r = deptLinkService.getDeptName();
        List<SysDeptNameForCodeVO> list = r.getData();
        List<SysDeptNameForCodeVO> sysDeptNameForCodeVOS = list.stream().filter(a -> a.getOrganizationCode().equals(mineCode)).collect(Collectors.toList());
        if (sysDeptNameForCodeVOS.size()==0){
            return "";
        }else {
            SysDeptNameForCodeVO sysDeptNameForCodeVO = sysDeptNameForCodeVOS.get(0);
            return sysDeptNameForCodeVO.getDeptName();

        }
    }
}
